#' 绘制差分方程的根的轨迹
#'
#' @param n 迭代次数

draw_de <- function(A,b,n = 10,init_x = matrix(c(0.1,0.2),2)){
  lmd <- diag(eigen(A)$values)
  P <- eigen(A)$vector
  barX <- -solve(A) %*% b

  xt <- matrix(NA,n,2)
  for (i in 1:n) {
    ans <- P %*% (lmd^i) %*% solve(P) %*% (init_x - barX) + barX
    xt[i,] <- t(ans)
  }

  xt <- apply(xt,2, as.numeric) %>% as.data.frame()
  p <- ggplot(xt, aes(x = 1:n, y = V1)) + geom_line() +
    geom_line(aes(y = V2), color = I('red'))
  sprintf('两个稳态分别为 %f 和 %f, 特征值为',barX[1], barX[2]) %>% print()
  print(diag(lmd))
  return(p)
}
